#!/usr/bin/env python
# -*- coding:utf-8 -*-
from django.shortcuts import render
from app01.forms import home as HomeForm

from app01 import models
def index(request):
    ret = models.SimpleModel.objects.all()
    print ret   #[<SimpleModel: SimpleModel object>, ]对象的列表
    print type(ret)     #<class 'django.db.models.query.QuerySet'>
    print ret.query     #SELECT "id", "username","password" FROM "app01_simplemodel"
    print models.SimpleModel.objects.all().values("username")
        #[{'username': u'user1'}, {'username': u'user2'}, {'username': u'user3'}]
    print models.SimpleModel.objects.all().values_list("id","username")
        #[(1, u'user1'), (2, u'user2'), (3, u'user3')]
        #正是form--select的格式
    # dic = {"username":"user1","password":"123"}
    # models.SimpleModel.objects.create(**dic)

    # models.UserInfo.objects.all().delete()
    # models.UserInfo.objects.create(name='user1')
    # after_list = models.UserInfo.objects.all()
    # print after_list[0].ctime
    #
    obj = HomeForm.ImportForm(request.POST)
    return render(request,'home/index.html',{'obj':obj})